#include "rnet.h"
#include "server_loop_task.h"
#include "app_service.h"
#include "server_service.h"
#include "com_service.h"

#include <json/reader.h>
#include <json/json.h>
using namespace	Json ;

int gi_server_heartbeat = 30 ;

void server_loop_task::run()
{
	while( true )
	{
		Value root;
		if( app_service::_instance().mp_control_task != NULL )
		{
			root["control_sn"] = app_service::_instance().mp_control_task->ms_sn;
			root["control_version"]= app_service::_instance().mp_control_task->ms_version ;
			root["control_vender"]= app_service::_instance().mp_control_task->ms_vender ;
		}
		else
		{
			root["control_sn"] = "";
			root["control_version"]= "" ;
			root["control_vender"]= "" ;
		}
		
		root["ble_sn"]= com_service::_instance().m_task.ms_sn ;
		root["ble_version"]= com_service::_instance().m_task.ms_version ;
		root["ble_vender"]= com_service::_instance().m_task.ms_vender ;

		if ( !server_service::_instance().write(root.toStyledString()) ) 
			rlog << "server_service.write() error" << endl ;

		sleep(gi_server_heartbeat) ;
	}
}

